package weifei.wx.community;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import weifei.wx.community.interceptor.AdminerTokenInterceptor;
import weifei.wx.community.interceptor.UserTokenInterceptor;
import weifei.wx.community.interceptor.WXTestInterceptor;


@Configuration
public class ApplicationConfiguration implements WebMvcConfigurer
{
    @Bean
    public CharacterEncodingFilter characterEncodingFilter(){
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        return filter;
    }


    public void addInterceptors(InterceptorRegistry registry)
    {
//        registry
//                .addInterceptor(new WXTestInterceptor())
//                .addPathPatterns("/**");

        registry
                .addInterceptor(new AdminerTokenInterceptor())
                .addPathPatterns("/db/**");

        registry.addInterceptor(new UserTokenInterceptor())
                .addPathPatterns("/user/**")
                .excludePathPatterns("/user/verifyAccessToken")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/getUser")
                .excludePathPatterns("/user/getNickname")

                .addPathPatterns("/tie/publish")
                .addPathPatterns("/tie/deleteTieByID")
                .addPathPatterns("/tie/comment/publish")
                .addPathPatterns("/tie/comment/reply/publish")

                .addPathPatterns("/tie/comment/notice/**")
                .addPathPatterns("/tie/comment/reply/notice/**");
    }
}



